<?php
header("Content-Type: text/html; charset=utf-8");
?>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--  1.bootstrap引入  -->
    {{--<link href="{{ asset('/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">--}}
</head>

<meta name="csrf-token" content="{{ csrf_token() }}">
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>

<center>

<table border="1">

    {{--<form action="test_do" method="get">--}}
    <tr>
        <td>用户名：</td>
        <td><input type="text" name="username"/></td>
    </tr>
    <tr>
        <td>密码：</td>
        <td><input type="text" name="pwd"/></td>
    </tr>
    <tr>
        <td><input type="button" value="提交" id="bto"/></td>
    </tr>
    {{--</form>--}}

</table>

</center>

<script>

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    // 获取 token
    var _token = $('meta[name="csrf-token"]').attr('content');

    $("#bto").click(function(){
        var name = $("input[name='username']").val();
        var pwd = $("input[name = 'pwd']").val();
        var url = "{{ url('/test/doinsert') }}";
        if(name==""){
           alert("用户名不能为空");die;
        }
        if(pwd==""){
            alert("密码不能为空");die;
        }
//        alert(url)
        $.ajax({
            type:'post',
            url:url,
            data:{
                name:name,
                pwd:pwd,
                _token:_token
            },
            async:true,
            dataType:"json",
            success:function(msg){
                if(msg==1){
                    alert("添加成功");location.href='/test/show';
                }
                if(msg==0){
                    alert("添加失败");
                }
            }
        })
    })


</script>